<?php
namespace lib;
/**
 * 数据验证
 */
class verify extends \i
{

    static function regex($value, $rule)
    {
        $validate = array(
            'require'   => '/.+/',
            'email'     => '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',
            'url'       => '/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/',
            'currency'  => '/^\d+(\.\d+)?$/',
            'number'    => '/^\d+$/',
            'zip'       => '/^\d{6}$/',
            'integer'   => '/^[-\+]?\d+$/',
            'double'    => '/^[-\+]?\d+(\.\d+)?$/',
            'english'   => '/^[A-Za-z]+$/',
            'commpwd'   => '/^\S{6,20}$/',
            'communame' => '/^[\x{2e80}-\x{9fff}\w]{3,11}$/u',
            'discuss_dir' => '/^[\x{2e80}-\x{9fff}\w]{2,10}$/u',
        );
        // 检查是否有内置的正则表达式
        if (isset($validate[strtolower($rule)])) {
            $rule = $validate[strtolower($rule)];
        }
        return preg_match($rule, $value) === 1;
    }
}